package cn.hahah.module.blog.dal.mysql.article;

import java.util.*;

import cn.hahah.framework.common.pojo.PageResult;
import cn.hahah.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.hahah.framework.mybatis.core.mapper.BaseMapperX;
import cn.hahah.module.blog.dal.dataobject.article.ArticleDO;
import org.apache.ibatis.annotations.Mapper;
import cn.hahah.module.blog.controller.admin.article.vo.*;

/**
 * 博客系统文章 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface ArticleMapper extends BaseMapperX<ArticleDO> {

    default PageResult<ArticleDO> selectPage(ArticlePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ArticleDO>()
                .eqIfPresent(ArticleDO::getUserId, reqVO.getUserId())
                .eqIfPresent(ArticleDO::getTypeId, reqVO.getTypeId())
                .eqIfPresent(ArticleDO::getTitle, reqVO.getTitle())
                .eqIfPresent(ArticleDO::getPicture, reqVO.getPicture())
                .eqIfPresent(ArticleDO::getContent, reqVO.getContent())
                .eqIfPresent(ArticleDO::getDescription, reqVO.getDescription())
                .eqIfPresent(ArticleDO::getViews, reqVO.getViews())
                .eqIfPresent(ArticleDO::getIsPublished, reqVO.getIsPublished())
                .eqIfPresent(ArticleDO::getIsRecommend, reqVO.getIsRecommend())
                .eqIfPresent(ArticleDO::getIsAppreciation, reqVO.getIsAppreciation())
                .eqIfPresent(ArticleDO::getIsCommentEnabled, reqVO.getIsCommentEnabled())
                .eqIfPresent(ArticleDO::getIsTop, reqVO.getIsTop())
                .betweenIfPresent(ArticleDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ArticleDO::getId));
    }

}